<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>诊断详情 - 智能医疗系统</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
    <!-- Vue.js -->
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.js"></script>
    <!-- 使用 BootCDN（国内加速） -->
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.6.5/axios.min.js"></script>
</head>
<body class="bg-light">
<div id="app" class="container mt-5">
    <h2 class="text-center mb-4">诊断详情</h2>
    <div v-if="appointment">
        <p><strong>预约ID:</strong> {{ appointment.id }}</p>
        <p><strong>医生:</strong> {{ appointment.doctor.name }}</p>
        <p><strong>班次:</strong> {{ appointment.schedule.dayOfWeek }}（{{ appointment.schedule.timeSlot }}）</p>
        <p><strong>状态:</strong> {{ appointment.status }}</p>
        <div v-if="appointment.medicalRecord">
            <p><strong>诊断:</strong> {{ appointment.medicalRecord.diagnosis }}</p>
            <p><strong>处方:</strong> {{ appointment.medicalRecord.prescription }}</p>
        </div>
        <div v-else>
            <p class="text-warning">暂无诊断信息</p>
        </div>
    </div>
    <div v-else>
        <p>加载中……</p>
    </div>
    <div class="mt-3">
        <a href="patient.html" class="btn btn-primary">返回患者面板</a>
    </div>
</div>

<script>
    new Vue({
        el: '#app',
        data: {
            appointment: null
        },
        methods: {
            fetchAppointment() {
                // 从 URL 中获取 appointmentId 参数
                const urlParams = new URLSearchParams(window.location.search);
                const appointmentId = urlParams.get('appointmentId');
                if (!appointmentId) {
                    alert("缺少 appointmentId 参数");
                    return;
                }
                axios.get('/patient/appointment/' + appointmentId)
                    .then(response => {
                        this.appointment = response.data;
                    })
                    .catch(error => {
                        console.error("获取预约详情失败：", error);
                    });
            }
        },
        mounted() {
            this.fetchAppointment();
        }
    });
</script>
</body>
</html>
